/**
 *  Copyright (C) 2013  Piotr Szczepański
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package edu.pw.elka.gtsna.weka_interface;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import edu.pw.elka.gtsna.graph.Graph;

import weka.core.Attribute;
import weka.core.DenseInstance;
import weka.core.Instances;

/**
 * @author Aleksy Barcz
 *
 */
public class NodeInstances extends Instances {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1493960162480852016L;
	
	protected Graph graph;
	protected Map<Integer, DenseInstance> nodes;
	
	public int size() {
		return nodes.size();
	}


	public NodeInstances(Graph gr) {
		super("nodeInstances",
				new ArrayList<Attribute>() {{ add(new Attribute("nodeIndex")); }},
				gr.getNumOfNodes()
		);
		graph = gr;
		nodes = new HashMap<Integer, DenseInstance>();
		for (int node: graph.getAllNodes()) {
			DenseInstance instance = new DenseInstance(1);
			instance.setValue(classIndex(), node);
			instance.setDataset(this);
			this.add(instance);
			nodes.put(node, instance);
		}
	}
	
	public final Graph getGraph() {
		return graph;
	}
	
	public final DenseInstance getNode(int nodeNumber) {
		return nodes.get(nodeNumber);
	}
	
	/** return the node number */
	@Override
	public int classIndex() {
		return 0;
	}

	/**
	 * @param source
	 * @param first
	 * @param toCopy
	 */
	public NodeInstances(Instances source, int first, int toCopy) {
		super(source, first, toCopy);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param dataset
	 * @param capacity
	 */
	public NodeInstances(Instances dataset, int capacity) {
		super(dataset, capacity);
		// TODO Auto-generated constructor stub
	}


	/**
	 * @param dataset
	 */
	public NodeInstances(Instances dataset) {
		super(dataset);
		// TODO Auto-generated constructor stub
	}

}
